<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
	<th:block th:include="include :: header('督查列表')" />
</head>
<body class="gray-bg">
	<div class="container-div">
		<div class="row">
			<div class="col-sm-12 search-collapse">
				<form id="role-form">
					<div class="select-list">
						<ul>
							<li>
								工程名称：<input type="text" name="projectName"/>
							</li>
							<li>
								风险等级：<input type="text" name="riskLevel"/>
							</li>
							<li>
								业主项目：<input type="text" name="ownerProjectDepartment"/>
							</li>
							<li class="select-time">
								<label>检查日期： </label><!--id="startTime"-->
								<input type="text" class="time-input" name="inspectionDate" readonly placeholder="检查日期" />
							</li>

							<li>
								<a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
							    <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
							</li>
						</ul>
					</div>
				</form>
			</div>
		
			<div class="btn-group-sm" id="toolbar" role="group">
				<a class="btn btn-success" onclick="$.operate.addTab()" shiro:hasPermission="inspection:add">
	                <i class="fa fa-plus"></i> 新增
	            </a>
	            <a class="btn btn-primary single disabled" onclick="$.operate.editTab()" shiro:hasPermission="inspection:edit">
		            <i class="fa fa-edit"></i> 修改
		        </a>
				<a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()" shiro:hasPermission="inspection:remove">
		            <i class="fa fa-remove"></i> 删除
		        </a>
<!--				<a class="btn btn-info" onclick="$.table.importExcel()" shiro:hasPermission="inspection:import">-->
<!--					<i class="fa fa-upload"></i> 导入-->
<!--				</a>-->

				<a class="btn btn-warning" onclick="exportSelected()">
					<i class="fa fa-download"></i> 导出
				</a>

<!--		        <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="inspection:export">-->
<!--		            <i class="fa fa-download"></i> 导出-->
<!--		        </a>-->
	        </div>
	        
	        <div class="col-sm-12 select-table table-striped">
			    <table id="bootstrap-table"></table>
			</div>
		</div>
	</div>
	<th:block th:include="include :: footer" />
	<script th:inline="javascript">
		var editFlag = [[${@permission.hasPermi('inspection:edit')}]];
		var removeFlag = [[${@permission.hasPermi('inspection:remove')}]];
		var prefix = ctx + "inspection";
		

		$(function() {
		    var options = {
		        url: prefix + "/list",
		        createUrl: prefix + "/add",
		        updateUrl: prefix + "/edit/{id}",
		        removeUrl: prefix + "/remove",
				importUrl: prefix + "/importData",
				importTemplateUrl: prefix + "/importTemplate",
		        exportUrl: prefix + "/export",
				sortName: "createTime",
				sortOrder: "desc",
		        modalName: "督查",
		        columns: [{
		            checkbox: true
		        },
		        {
		            field: 'inspectionId',
		            title: '督查编号'
		        },
		        {
		            field: 'inspectorName',
		            title: '督查人',
		            sortable: true
		        },
		        {
		            field: 'projectName',
		            title: '工程名称',
		            sortable: true,
					formatter: function(value, row, index) {
						return $.table.tooltip(value, 26, "open");
					}
		        },{
		            field: 'riskLevel',
		            title: '风险等级',
		            sortable: true
		        },
		        {
		            field: 'ownerProjectDepartment',
		            title: '业主项目部',
		            sortable: true
		        },
		        {
		            field: 'inspectionDate',
		            title: '检查日期',
		            sortable: true
		        },{
		            field: 'onSiteSupervisor',
		            title: '现场监理人员',
		            sortable: true
		        },
		        {
		            field: 'constructionUnit',
		            title: '施工单位',
		            sortable: true
		        },
		        {
		            field: 'onSiteWorkManager',
		            title: '现场工作负责人',
		            sortable: true
		        },{
		            field: 'constructionWorkContents',
		            title: '作业内容',
		            sortable: true,
					formatter: function(value, row, index) {
						return $.table.tooltip(value, 26, "open");
					}
		        },
		        {
		            field: 'constructionWorkersNumber',
		            title: '作业人数',
		            sortable: true
		        },{
		            field: 'formNumber',
		            title: '表单编号',
		            sortable: true
		        },{
		            field: 'generalInspectionStatus',
		            title: '总体检查情况',
		            sortable: true
		        },{
		            field: 'violationRemarks',
		            title: '违规备注',
		            sortable: true
		        },{
		            field: 'rectificationSuggestion',
		            title: '整改建议',
		            sortable: true
		        },
		        {
		            title: '操作',
		            align: 'center',
		            formatter: function(value, row, index) {
		            	if (row.roleId != 1) {
		                    var actions = [];
		                    actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.id + '\')"><i class="fa fa-edit"></i>编辑</a> ');
		                    actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.id + '\')"><i class="fa fa-remove"></i>删除</a> ');
		                    var more = [];
		                    more.push("<a class='btn btn-default btn-xs " + editFlag + "' href='javascript:void(0)' onclick='authDataScope(" + row.id + ")'><i class='fa fa-check-square-o'></i>数据权限</a> ");
		                    more.push("<a class='btn btn-default btn-xs " + editFlag + "' href='javascript:void(0)' onclick='authUser(" + row.id + ")'><i class='fa fa-user'></i>分配用户</a>");
		                    actions.push('<a tabindex="0" class="btn btn-info btn-xs" role="button" data-container="body" data-placement="left" data-toggle="popover" data-html="true" data-trigger="hover" data-content="' + more.join('') + '"><i class="fa fa-chevron-circle-right"></i>更多操作</a>');
		                    return actions.join('');
		            	} else {
		                    return "";
		                }
		            }
		        }]
		    };
		    $.table.init(options);
		});

		// 导出数据
		function exportSelected() {
			var inspectionIds = $.table.selectColumns("inspectionId");

			var dataParam = $("#export-form").serializeArray();
			var tipMsg = "确定导出所有数据吗？";
			if($.common.isNotEmpty(inspectionIds)){
				tipMsg = "确定导出勾选" + inspectionIds.length + "条数据吗？";
				dataParam.push({ "name": "inspectionIds", "value": inspectionIds });
			}
			// alert(inspectionIds)
			$.modal.confirm(tipMsg, function() {

				// $.post(prefix + "/export", dataParam, function(result) {
				$.post(prefix + "/downZip", dataParam, function(result) {
				// $.get(prefix + "/generateDocumentOfApi", dataParam, function(result) {
				// 	alert("result.code="+result.code)
					// alert("result="+result)
					// if (result.code == web_status.SUCCESS) {
					// 	window.location.href = ctx + "common/download?fileName=" + encodeURI(result.msg) + "&delete=" + true;
						window.location.href = ctx + "common/download?fileName=创成公司现场作业线上督查表.zip&delete=" + true;

						// window.location.href = ctx + "/generateDocumentOfApi?id="+inspectionId;
					// } else {
					// 	$.modal.alertError(result.msg);
					// }
					//下载后删除文件
					$.post(prefix + "/deleteFile", null, function(result) {
						console.log("删除成功")
					})
				});
			});
		}


		function queryDeptTree()
		{
			var url = ctx + "system/dept/treeData";
			var options = {
				url: url,
				expandLevel: 2,
				onClick : zOnClick
			};
			$.tree.init(options);

			function zOnClick(event, treeId, treeNode) {
				$("#deptId").val(treeNode.id);
				$("#parentId").val(treeNode.pId);
				$.table.search();
			}
		}
		/* 用户管理-部门 */
		function dept() {
			var url = ctx + "system/dept";
			$.modal.openTab("部门管理", url);
		}
		/* 督查管理-分配数据权限 */
		function authDataScope(id) {
		    var url = prefix + '/authDataScope/' + id;
		    $.modal.open("分配数据权限", url);
		}
		
		/* 督查管理-分配用户 */
		function authUser(id) {
		    var url = prefix + '/authUser/' + id;
		    $.modal.openTab("分配用户", url);
		}
		
		/* 督查状态显示 */
		function statusTools(row) {
		    if (row.status == 1) {
    			return '<i class=\"fa fa-toggle-off text-info fa-2x\" onclick="enable(\'' + row.id + '\')"></i> ';
    		} else {
    			return '<i class=\"fa fa-toggle-on text-info fa-2x\" onclick="disable(\'' + row.id + '\')"></i> ';
    		}
		}
		
		/* 督查管理-停用 */
		function disable(id) {
			// alert(id)
			$.modal.confirm("确认要停用督查吗？", function() {
				$.operate.post(prefix + "/changeStatus", { "id": id, "status": 1 });
		    })
		}

		/* 督查管理启用 */
		function enable(id) {
			$.modal.confirm("确认要启用督查吗？", function() {
				$.operate.post(prefix + "/changeStatus", { "id": id, "status": 0 });
		    })
		}
	</script>
</body>
<!-- 导入区域 -->
<script id="importTpl" type="text/template">
	<form enctype="multipart/form-data" class="mt20 mb10">
		<div class="col-xs-offset-1">
			<input type="file" id="file" name="file"/>
			<div class="mt10 pt5">
				<input type="checkbox" id="updateSupport" name="updateSupport" title="如果登录账户已经存在，更新这条数据。"> 是否更新已经存在的用户数据
				&nbsp;	<a onclick="$.table.importTemplate()" class="btn btn-default btn-xs"><i class="fa fa-file-excel-o"></i> 下载模板</a>
			</div>
			<font color="red" class="pull-left mt10">
				提示：仅允许导入“xls”或“xlsx”格式文件！
			</font>
		</div>
	</form>
</script>
</html>